home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
16
/
art.fth
< prev
next >
Wrap
Text File
|
1985-11-19
|
3KB
|
128 lines
\ String Art demo. Load this file then type stringart
\ Typing any key stops the demo.
needs line-a-init linea.fth
line-a-init
decimal
13 constant #functions
343 constant #artlines
#functions #artlines * constant #points
create function-points #points /w* allot
17 xbios: _random { -- l.rnd-number } \ bios random number routine
: rnd ( limit -- rndnum ) \ return random number up to limit
_random swap mod
;
: random ( -- n ) #functions rnd ;
\ Get a new random number that is different from the old one
: new-rand ( old-rand -- new-rand )
begin random ( old new )
2dup =
while drop
repeat
nip
;
: write-binary-points ( -- )
[""] stringpt.bin dup make drop
write open ofd !
function-points #points /w* ofd @ fputs
ofd @ close
;
defer test ' noop is test
\ Read the ascii version of the function tables and write it back out
\ as a binary file
: read-points ( -- )
[""] stringpt.num read open ifd !
hex
function-points #points /w*
bounds
?do
pad ifd @ getword test
number? 0= abort" bogus"
i w!
/w +loop
ifd @ close
write-binary-points
;
\ Read in the binary version of the function tables
: read-binary-points ( -- )
[""] stringpt.bin read open ifd !
function-points #points /w* tuck ifd @ fgets
<> if ." Read failed" cr then
ifd @ close
;
variable xs variable ys \ Starting endpoint for a line
variable xe variable ye \ Ending endpoint for a line
\ Find the starting address for the index'th function in the function
\ table
: >function ( index -- table-address )
#artlines * /w* function-points +
;
\ Coefficients for transforming to the screen coordinate system
wvariable xscale wvariable yscale
wvariable xoffset wvariable yoffset
: set-scaling ( -- )
get-rez ( xmax ymax )
2dup
9 10 */ yscale w!
9 10 */ xscale w! ( xmax ymax )
20 / yoffset w!
20 / xoffset w!
;
\ Transform normalized device coordinates to screen coordinates
code ndc>device ( x y -- x' y' )
sp )+ d1 move \ y
sp )+ d0 move \ x
xscale l#) d0 mulu
yscale l#) d1 mulu
d0 d0 add
d1 d1 add
d0 word clr normal
d0 swap
d1 word clr normal
d1 swap
word xoffset l#) d0 add normal
word yoffset l#) d1 add normal
d0 sp -) move
d1 sp -) move
c;
: nextw ( variable -- w )
dup @ w@ /w rot +!
;
: draw-line ( -- )
xs nextw ys nextw ndc>device ( startxy )
xe nextw ye nextw ndc>device ( startxy endxy )
draw
;
: stringart
set-scaling
0 _wrt_mod w!
erase-screen
begin
random dup >function xs ! new-rand >function xe !
random dup >function ys ! new-rand >function ye !
xs @ ys @ xe @ ye @
#artlines 0 do draw-line loop
ye ! xe ! ys ! xs !
_fg_bp_1 w@ 0 _fg_bp_1 w!
#artlines 0 do draw-line loop
_fg_bp_1 w!
key? until
;
read-binary-points
ö}Γ~,~q~»~ΩM